package main

import "fmt"

/**
 * @Description
 * @Author huran
 * @Date
 * @Param
 * @return
 **/

func Func4() {

}
func Use() {
	//函数可以赋值给变量
	myFunc := Func4
	myFunc()
}
func Func5() string {
	fn := func(name string) string {
		return "hello"
	}
	return fn("撒谎比")
}

func Func6() func() string {
	return func() string {
		return "jello"
	}
}

// 匿名方法立刻发起调用
func Func7() {
	fn := func() string {
		return "AAA"
	}()
	println(fn)
}

// 绑定上下文 闭包
func Closure(name string) func() string {
	return func() string {
		return "hello" + name
	}
}
func Closure1() func() string {
	age := 23
	name := "AAA"
	return func() string {
		fmt.Println("AAAAAAAAAAAAA")
		sprintf := fmt.Sprintf("Hello %s,%d", name, age)
		println(sprintf)
		return sprintf
	}
}

func DeferV1(a int) int {
	a = 0
	defer func() {
		a = 1
	}()
	return a
}
func DeferV2() int {
	a := 0
	defer func() {
		a = 1
	}()
	return a
}
func main() {
	println(DeferV2())
}
